<template>
  <div>
    <avue-form v-model="searchForm" :option="searchFormOption">
      <template slot="deviceOperateNum">
        <div>{{ stTicketPettyAdd.deviceOperateNum }}</div>
      </template>
      <template slot="totalSpareAmount">
        <div>{{ stTicketPettyAdd.totalSpareAmount }}</div>
      </template>
       <template slot="totalHandSpareAmount">
        <div>{{ stTicketPettyAdd.totalHandSpareAmount }}</div>
      </template>
    </avue-form>
    <avue-form v-model="form" :option="formOption" @submit="submit"></avue-form>
  </div>
</template>

<script>
import {
  getNeedConfirmData,
  confirm
} from "@/api/subwaystm/swstticketpettyadd";
import { checkPwd } from "@/api/admin/user";
import { dateFormat } from "@/util/date";
export default {
  name: "ticketPettyAdd",
  data() {
    return {
      searchForm: {
        date: dateFormat(new Date()).substr(0, 10)
      },
      stTicketPettyAdd: {},
      form: {},
      searchFormOption: {
        labelWidth: 120,
        menuBtn: false,
        group: [
          {
            label: "",
            column: [
              {
                label: "设备操作号",
                prop: "deviceOperateNum",
                type: "input",
                span: 6,
                formslot: true
              },
              {
                label: "配备用金金额",
                prop: "totalSpareAmount",
                type: "input",
                span: 6,
                formslot: true
              },
	      {
                label: "归还备用金金额",
                prop: "totalHandSpareAmount",
                type: "input",
                span: 6,
                formslot: true
              }

            ]
          }
        ]
      },
      formOption: {
        submitBtn: false,
        emptyBtn: false,
        group: [
          {
            label: "配票明细",
            column: [
              {
                type: "dynamic",
                prop: "ticketDetailsFirst",
                labelPosition: "top",
                span: 24,
                disabled: true,
                children: {
                  align: "center",
                  headerAlign: "center",
                  column: [
                      {
                      label: '票种',
                      prop: 'ticketName',
                      type: 'select',
                      dicUrl:'/support/swpmticketcardtype/dict/ticket',
                       props: {
                        label: 'mainName',
                        value: 'mainEnName'
                      },
                    },
                    {
                      label: "车票名称",
                      prop: "ticketType",
                      type: "select",
                      dicUrl: "/support/swpmticketcardtypeparam/dict/{{key}}",
                      props: {
                        label: "subName",
                        value: "subEnName"
                      }
                    },
                    {
                      label: "金额/次数",
                      prop: "ticketValue",
                      formatter: function(row, value, label, column) {
                        debugger;
                        return `${
                          row.ticketValue == null ? "" : row.ticketValue
                        }${row.ticketUnit || ""}`;
                      }
                    },
                    {
                      label: "开窗张数",
                      prop: "windowsNum",
                      type: "number"
                    },
                    {
                      label: "关窗张数",
                      prop: "windowsCloseNum",
                      type: "number",
                      display: false,
                      hide: true
                    }
                  ]
                }
              }
            ]
          },
          {
            label: "新增配备用金明细",
            column: [
              {
                type: "dynamic",
                prop: "cashDetailsNewAdd",
                labelPosition: "top",
                span: 24,
                disabled: true,
                children: {
                  align: "center",
                  headerAlign: "center",
                  column: [
                    {
                      label: "配票款金额",
                      prop: "spareAmount",
                      type: "number",
                      precison: 2
                    },
                    {
                      label: "操作时间",
                      prop: "createTime",
                      type: "datetime",
                      format: "yyyy-MM-dd HH:mm:ss",
                      valueFormat: "yyyy-MM-dd HH:mm:ss"
                    }
                  ]
                }
              }
            ]
          },
          {
            label: "新增配票明细",
            column: [
              {
                type: "dynamic",
                prop: "ticketDetailsNewAdd",
                labelPosition: "top",
                span: 24,
                disabled: true,
                children: {
                  align: "center",
                  headerAlign: "center",
                  column: [
                      {
                      label: '票种',
                      prop: 'ticketName',
                      type: 'select',
                      dicUrl:'/support/swpmticketcardtype/dict/ticket',
                       props: {
                        label: 'mainName',
                        value: 'mainEnName'
                      },
                    },
                    {
                      label: "车票名称",
                      prop: "ticketType",
                      type: "select",
                      dicUrl: "/support/swpmticketcardtypeparam/dict/{{key}}",
                      props: {
                        label: "subName",
                        value: "subEnName"
                      }
                    },
                    {
                      label: "金额/次数",
                      prop: "ticketValue",
                      formatter: function(row, value, label, column) {
                        return `${
                          row.ticketValue == null ? "" : row.ticketValue
                        }${row.ticketUnit || ""}`;
                      }
                    },
                    {
                      label: "新增开窗数量（张）",
                      prop: "windowsNum",
                      type: "number"
                    },
                    {
                      label: "操作时间",
                      prop: "createTime",
                      type: "datetime",
                      format: "yyyy-MM-dd HH:mm:ss",
                      valueFormat: "yyyy-MM-dd HH:mm:ss"
                    }
                  ]
                }
              }
            ]
          },{
            label: "归还明细",
            column: [
              {
                type: "dynamic",
                prop: "ticketDetailsReturn",
                labelPosition: "top",
                span: 24,
                disabled: true,
                children: {
                  align: "center",
                  headerAlign: "center",
                  column: [
                      {
                      label: '票种',
                      prop: 'ticketName',
                      type: 'select',
		      width: 120,
                      dicUrl:'/support/swpmticketcardtype/dict/ticket',
                       props: {
                        label: 'mainName',
                        value: 'mainEnName'
                      },
                    },
                    {
                      label: "车票名称",
                      prop: "ticketType",
		      width: 120,
                      type: "select",
                      dicUrl: "/support/swpmticketcardtypeparam/dict/{{key}}",
                      props: {
                        label: "subName",
                        value: "subEnName"
                      }
                    },
                    {
                      label: "金额/次数",
                      prop: "ticketValue",
                      formatter: function(row, value, label, column) {
                        debugger;
                        return `${
                          row.ticketValue == null ? "" : row.ticketValue
                        }${row.ticketUnit || ""}`;
                      }
                    },
                    {
                      label: "开窗张数",
                      prop: "windowsNum",
                      type: "number"
                    },
                    {
                      label: "关窗张数",
                      prop: "windowsCloseNum",
                      type: "number"
                    }, {
                      type: "number",
                      label: "废票张数 ",
                      prop: "invalidTicketNum"
                    }, {
                      type: "number",
                      label: "即时替换张数 ",
                      prop: "replaceTicketNum"
                    }, {
                      type: "number",
                      label: "现金售卖张数 ",
                      prop: "cashSaleNum"
                    }, {
                      type: "number",
                      label: "现金售卖金额 ",
                      prop: "cashSaleAmount"
                    }, {
                      type: "number",
                      label: "微信售卖张数 ",
                      prop: "wechatSaleNum"
                    }, {
                      type: "number",
                      label: "微信售卖金额 ",
                      prop: "wechatSaleAmount"
                    }, {
                      type: "number",
                      label: "支付宝售卖张数 ",
                      prop: "alipySaleNum"
                    }, {
                      type: "number",
                      label: "支付宝售卖金额 ",
                      prop: "alipySaleAmount"
                    }, {
                      type: "number",
                      label: "POS机售卖张数 ",
                      prop: "posSaleNum"
                    }, {
                      type: "number",
                      label: "POS机售卖金额 ",
                      prop: "posSaleAmount"
                    }, {
                     hide:true,
                    "type": "select",
                    "label": "POS卡类型",
                    "prop": "posCardType",
                     width: 180,
                     dicUrl:'/admin/dict/type/pos_card_type'
                  }
                  ]
                }
              }
            ]
          }
        ]
      }
    };
  },
  computed: {},
  methods: {
    getData(searchForm) {
      getNeedConfirmData(searchForm).then(response => {
        let s = response.data.data;
        if(!this.validatenull(s.stTicketPettyAdd)){
          if(s.stTicketPettyAdd.deviceAttribution == "0") {
            this.$message.warning("该售票员有未归还的配票与配备用金数据，请先归还配票数据再进行值站确认");
          }
        }
        this.form = response.data.data || {};
        this.stTicketPettyAdd = this.form.stTicketPettyAdd || {};
      });
    },
    submit(form, done) {
      if (!this.searchForm.nsJobNo) {
        this.$message.info("请选择售票员");
        done();
        return;
      }
      this.$prompt("请输入售票员密码", "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "password",
        inputValidator: val => {
          if (!val) return "请输入密码";
        }
      })
        .then(({ value }) => {
          return checkPwd(this.searchForm.nsJobNo, value);
        })
        .then(response => {
          var result = response.data.data;
          if (result) {
            return;
          } else {
            this.$message.error("密码错误");
            return Promise.reject("密码错误");
          }
        })
        .then(() => {
          return confirm(this.stTicketPettyAdd.id);
        })
        .then(() => {
          this.getData();
          this.$message.success("确认成功");
          done();
        })
        .catch(error => {
          console.log(error);
          done();
        });
    }
  }
};
</script>

<style lang="scss"></style>
